from datetime import datetime
import io
import json
import logging
import threading
import uuid
from django.shortcuts import redirect, render
import requests
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from doc_service.models import Report
from doc_service.views import centimeter_transformation_point
from reportservice.helpers import ApiResponse
from yida_app_service.utils.xmutils import generate_random_string
from yida_app_service.views import get_xm_client
from yida_app_service.xu_cloud_client import XmCloudBaseClient
from yida_app_service.xu_digital_sign_client import XmDigitalSignBaseClient
from .yida_config import YidaClient
from oss_service.views import digital_bucket as bucket
from oss_service.views import bucket as yida_bucket
from django.core.cache import cache
from oss_service.views import bucket, digital_bucket
import PyPDF2

logger = logging.getLogger(__name__)
yida_client = YidaClient()
admin_user_id = "301546025724261514"
digital_sign_client = XmDigitalSignBaseClient()
def get_userinfo_by_ding(dingtalk_user_id:str):
    '''
        通过钉钉用户ID获取用户信息
    '''
    url = 'https://api.zjcxjc.cn/api/v1/digital-sign/get-personinfo-by-dingtalk-id'
    query_params = {
        'dingtalkUserId': dingtalk_user_id
    }
    # 发送GET请求并传递参数
    response = requests.get(url, params=query_params)
    if response.status_code == 200:
        # 解析响应内容
        data = response.json()
        if data.get('code') == 200:
            return data.get('data')
    return None

def get_sign_order(orderNo:str):
    url = 'https://api.zjcxjc.cn/api/v1/digital-sign/get-sign-order'
    query_params = {
        'orderNo': orderNo
    }
    # 发送GET请求并传递参数
    response = requests.get(url, params=query_params)
    if response.status_code == 200:
        # 解析响应内容
        data = response.json()
        if data.get('code') == 200:
            return data.get('data')
    return None

def face_recognition(request):
    context = {'message': " World!"}
    report_codes = request.GET.get("report_codes", "").replace("\u200b", "")
    sign_order_no = request.GET.get("signOrderNo", "").replace("\u200b", "")
    dingtalk_user_id = request.GET.get("dingtalkUserId", "").replace("\u200b", "")
    userinfo = get_userinfo_by_ding(dingtalk_user_id)
    report_codes_list = report_codes.split("_") if report_codes else []
    if len(report_codes_list)>0: 
       reports = Report.objects.filter(report_code__in=report_codes_list)
       sign_order_nos_list = [report.digital_sign_order_no for report in reports if report.digital_sign_order_no]
    else:
       sign_order_nos_list = []
    if len(sign_order_nos_list) > 0:
        sign_order = get_sign_order(sign_order_nos_list[0])
    else:
        sign_order = get_sign_order(sign_order_no)
    print('sign_order',sign_order)
    url = "https://api.zjcxjc.cn/api/v1/digital-sign/sign-coordinate-by-dingtalk-userid-in-pass-time"
    data = {
        "dingtalkUserId": dingtalk_user_id,
        "orderNo":sign_order_no
    }
    if userinfo:
        if len(sign_order_nos_list) > 0:   
            context = {
                "dingtalk_user_id":dingtalk_user_id,
                "personInformationPath": sign_order['contractFilePath'],
                "userId": userinfo['userId'],
                "signOrderNos":"_".join(sign_order_nos_list)
            }
            print('context--->',context)
            return render(request, 'face_compare_page.html',context)
        else:
            context = {
                "dingtalk_user_id":dingtalk_user_id,
                "personInformationPath": sign_order['contractFilePath'],
                "userId": userinfo['userId'],
                "signOrderNo":sign_order_no
            }
            print(context)
            response = requests.post(url, json=data)
            if response.status_code == 200:
                res = response.json()
                if res.get('code') == 200:
                    print('200', res.get('data'))
                    return render(request, 'success.html', {
                        'signRecordId': res.get('data')
                    })     
                if res.get('code') == 400:
                    print('400')
                    return render(request, 'face_compare_page.html',context)
    else:
        # return 
        # 跳转电子签章开户
        redir_url = "https://fpizp0.aliwork.com/APP_R3U6VT51DXVY8NTP4I0Z/workbench/FORM-9EE03F3F800F4E66A0A19007A740E7C0SI1Q"
        return redirect(redir_url)
    

@csrf_exempt
@require_http_methods(["POST"])
def signup_person(request):
    '''
        用户开户
    '''
    url = r'https://api.zjcxjc.cn/api/v1/digital-sign/signup-person'
    data: dict[str, any] = json.loads(request.body)
    response = requests.post(url, json=data)
    print(response)
    if response.status_code == 200:
        res = response.json()
        if res.get('code') == 200:
            sign_user_id = res.get('data')
            dingtalkUserId = data.get("dingtalkUserId")
            res = yida_client.get_form_data_by_search_field(form_uuid="FORM-861F9E6F4AAE4D73A255247BF7991765XAKG",
                                                      userId=admin_user_id,
                                                      search_field=[
                                                        {
                                                          "type": "TEXT",
                                                          "operator": "eq",
                                                          "componentName": "TextField",
                                                          "key": "textField_lp0zbal4",
                                                          "value": dingtalkUserId
                                                        }
                                                      ])
            if res:
                sealfile_url = res[0].form_data.get('digitalSignatureField_lp0tv65b')
                response = requests.get(sealfile_url)
                if response.status_code == 200:
                    userinfo = get_userinfo_by_ding(dingtalkUserId)
                    key = f"{userinfo['personInformationPath']}seal.png"
                    digital_bucket.put_object(key,response.content)
                    return ApiResponse.success(sign_user_id)
    return ApiResponse.fail(message="失败")


@csrf_exempt
@require_http_methods(["GET"])
def start_digital_sign(request):
    print('人脸视频上传成功，发起识别')
    order_no = request.GET.get("orderNo")
    dingtalk_user_id = request.GET.get("dingtalkUserId")
    face_video_path = request.GET.get("faceVideoPath")
    url = f'https://api.zjcxjc.cn/api/v1/digital-sign/sign-coordinate-by-dingtalk-userid'
    data = {
        "orderNo":order_no,
        "dingtalkUserId":dingtalk_user_id,
        "faceVideoPath":face_video_path
    }
    response = requests.post(url,json=data)
    # print(response)
    if response.status_code == 200:
        res = response.json()
        return ApiResponse.success(data=res,message="成功")
    else:
        return ApiResponse.fail(message="失败")
    
    
@csrf_exempt
@require_http_methods(["GET"])
def start_digital_signs(request):
    print('人脸视频上传成功，发起识别--批量')
    orderNos = request.GET.get("orderNos")
    dingtalk_user_id = request.GET.get("dingtalkUserId")
    face_video_path = request.GET.get("faceVideoPath")
    sign_order_nos_list = orderNos.split("_") if orderNos else []
    url = f'https://api.zjcxjc.cn/api/v1/digital-sign/batch-sign-coordinate-by-dingtalk-userid'
    data = {
        "orderNos":sign_order_nos_list,
        "dingtalkUserId":dingtalk_user_id,
        "faceVideoPath":face_video_path
    }
    response = requests.post(url,json=data)
    print(response)
    if response.status_code == 200:
        res = response.json()
        print(res)
        return ApiResponse.success(data=res,message="成功")
    else:
        return ApiResponse.fail(message="失败")
    
    
    
def face_register(request):
    context = {'message': " World!"}
    dingtalk_user_id = request.GET.get("dingtalkUserId")
    userinfo = get_userinfo_by_ding(dingtalk_user_id)
    print(userinfo['faceVerify'])
    if userinfo and userinfo['faceVerify'] == False:
        context = {
            "dingtalk_user_id":dingtalk_user_id,
            "personInformationPath":userinfo['personInformationPath'],
            "userId": userinfo['userId'],
        }
        print(context)
        return render(request, 'face_compare_page.html',context)
    else:
        return ApiResponse.success("您已录入过人脸信息，无需重新录入")

    
@csrf_exempt
@require_http_methods(["POST"])
def sign_order_completed(request):
    data = json.loads(request.body)
    sign_order_no = data.get("orderNo")
    submitUserDingtalkId = data.get("submitUserDingtalkId")
    if not sign_order_no:
        return ApiResponse.error(message="未传递订单编号-orderNo")
    try:
        report = Report.objects.get(digital_sign_order_no=sign_order_no)
    except Report.DoesNotExist:
        return ApiResponse.error(message="未找到该报告")
    res = yida_client.get_form_data_by_search_field(
        form_uuid="FORM-0BC04FECE4F544B297D37901915570D2OEIY",
        userId=admin_user_id,
        search_field={"textField_lp93kxup": report.report_code}
    )
    if not res:
        return ApiResponse.error(message="宜搭中未找这条数据")
    formInstId = res[0].form_instance_id
    signInformation = json.loads(res[0].form_data.get('textField_ltmlzgdv', "{}"))
    if submitUserDingtalkId in signInformation.get("participants_p_list", []):
        signInformation["participants_p_list"] = [id for id in signInformation["participants_p_list"] if id != submitUserDingtalkId]
        yida_client.update_form_data_by_id(
            form_uuid="FORM-0BC04FECE4F544B297D37901915570D2OEIY",
            userId=admin_user_id,
            form_inst_id=formInstId,
            update_field={"textField_ltmlzgdv": json.dumps(signInformation)}
        )
    if not data.get("totalSigner"):
        return ApiResponse.success(message="已确认签署")
    if data.get("totalSigner") == data.get("signedNum"):
        sign_file_path = data.get("outputFilePath")
        if sign_file_path:
            yida_bucket.copy_object(
                "xu-digital-sign", sign_file_path, report.report_path + '/signed.pdf')
            return ApiResponse.success(message="total success")
        else:
            return ApiResponse.fail(message="outputFilePath is required.")
    return ApiResponse.success(message="sign success")


@csrf_exempt
@require_http_methods(["POST"])
def sign_order_completed_daily_paper(request):
    data: dict[str, any] = json.loads(request.body)
    if(data["totalSigner"] == data["signedNum"]):
        sign_file_path = data["outputFilePath"]
        sign_order_no = data["orderNo"]
        daily_paper_data = yida_client.get_form_data_by_search_field(
            form_uuid="FORM-861219708B7A49A7B9BA2A25A53965ACYDQU",
            userId=admin_user_id,
            search_field={
                "textField_lvuq4bsd":sign_order_no
            }
        )
        url = json.loads(daily_paper_data[0].form_data['attachmentField_lvkjxzeg'])[0]['url']
        parts = url.split("download_file/")
        if len(parts) > 1:
            wholePDF_ossUrl = parts[1]
            print(wholePDF_ossUrl)
            # out-pdf/202405/4cf46c79-7a9a-419d-b742-bbfea57dda02/origin.pdf
        else:
            print("未找到该报告的oss路径")
        yida_bucket.copy_object(
                "xu-digital-sign", sign_file_path, wholePDF_ossUrl)
        return ApiResponse.success(message="total success")
    else:
        return ApiResponse.success(message="single success")
    

@csrf_exempt
@require_http_methods(["GET"])
def get_verify_code(request):
    report_code = request.GET.get("report_code")
    verify_code = generate_random_string(16)
    cache.set(f"verify_code:chengxiang:{verify_code}",report_code, 60*60*24)
    return ApiResponse.success(verify_code)

@csrf_exempt
@require_http_methods(["GET"])
def get_report_id_by_verify_code(request):
    verify_code = request.GET.get("verify_code")
    report_code = cache.get(f"verify_code:chengxiang:{verify_code}")
    if report_code is None:
        return ApiResponse.fail(message="验证码无效或已过期")
    # https://fpizp0.aliwork.com/APP_R3U6VT51DXVY8NTP4I0Z/processDetail?formUuid=FORM-0BC04FECE4F544B297D37901915570D2OEIY&procInsId=0a1abc30-568b-434d-bdb7-3200bf67a17b&isAdmin=true&navConfig.layout=1180
    else:
        result = yida_client.get_ids_by_search_field("FORM-0BC04FECE4F544B297D37901915570D2OEIY",admin_user_id,[{
            "type": "TEXT",
            "operator": "eq",
            "componentName": "TextField",
            "key": "textField_lp93kxup",
            "value": report_code
        }])
        if result:
            return ApiResponse.success(result[0])
        else:
            return ApiResponse.fail("未找到报告")


@csrf_exempt
@require_http_methods(["POST"])
def create_sign_order_by_yida_form(request):
    req_data = json.loads(request.body)
    form_uuid = req_data.get("form_uuid")
    form_inst_id = req_data.get("form_inst_id")
    pdf_component_id = req_data.get("pdf_component_id") # 签署pdf
    xm_model_id = req_data.get("xm_model_id")
    sign_component_id = req_data.get("sign_component_id")
    XmCloudClient = get_xm_client("chengxiang")
    sign_nodes:list = req_data.get("sign_nodes") # 审批节点
    if isinstance(sign_nodes, str):
        sign_nodes:list = json.loads(sign_nodes)
    # 获取审批记录
    app_history = yida_client.get_approve_history(form_inst_id,admin_user_id)
    # if app_history:
    #     pass
    xm_client:XmCloudBaseClient = XmCloudClient()
    xm_render_model_result = xm_client.get_render_model_info(xm_model_id)
    participants_personal = []
    if xm_render_model_result.get("code") == 200:
        sign_areas = xm_render_model_result.get("data").get("sign_area")
        # 下载待签署pdf文件
        yida_instance = yida_client.get_form_items_by_ids(form_uuid,form_inst_id,admin_user_id)
        if yida_instance:
            yida_instance = yida_instance[0]
        if not yida_instance.form_data.get(pdf_component_id):
            return ApiResponse.fail("请先生成或上传pdf")
        pdf_attachment = json.loads(yida_instance.form_data.get(pdf_component_id))
        download_url:str = pdf_attachment[0].get("downloadUrl")
        if not download_url.startswith("https://api.zjcxjc.cn"):
            full_download_url = yida_client.get_full_download_url(admin_user_id,download_url)
            download_url = full_download_url.body.result
        with requests.Session() as session:  # 使用 requests 库创建一个会话对象，用于发送 HTTP 请求。
            response = session.get(download_url)  # 发送 GET 请求以获取文件内容。
            if response.status_code == 200:
                file_content = response.content
        for sign_area in sign_areas:
            node_name = sign_nodes.pop(0)
            node = next((item for item in reversed(app_history) if item.show_name == node_name), None)
            if( sign_area['page'] < 0):
                pdf_file = io.BytesIO(response.content)
                pdf_reader = PyPDF2.PdfReader(pdf_file)
                total_pages = len(pdf_reader.pages)
                sign_area['page'] = total_pages + sign_area['page'] +1 # -1对应最后一页，以此类推
            participant = {
                "userType": "2",
                "dingtalkUserId": node.operator_user_id,
                "coordinate": rf"[{{lby:{centimeter_transformation_point(sign_area['y_axis'])},lbx:{centimeter_transformation_point(sign_area['x_axis'])},rty:{centimeter_transformation_point(sign_area['y_axis']) + centimeter_transformation_point(sign_area['size'])},rtx:{centimeter_transformation_point(sign_area['x_axis']) + centimeter_transformation_point(sign_area['size'])},page:{sign_area['page']}}}]"
            }
            if sign_area.get("seal"):
                seal = sign_area.get("seal")
                seal_url = seal[0].get("url")
                sealFilePath = f'file_tmp/{datetime.now().strftime("%Y%m%d")}/{uuid.uuid4()}.png'
                digital_bucket.copy_object("xu-bk-chengxiang", seal_url,sealFilePath)
                participant["sealFilePath"] = sealFilePath
            if sign_area.get("y_seal"):
                participant["coordinateRiding"] = f"{centimeter_transformation_point(sign_area['y_seal'])}F,{sign_area['size']}F"
            participants_personal.append(participant)
        res = digital_sign_client.create_order({
            "participants":participants_personal
        })
        if (res["code"] == 200):
            digital_bucket.put_object(res['data']['contractFilePath']+'origin.pdf', file_content)
            ds_no = res["data"]["orderNum"]
            yida_client.update_form_data_by_id(form_uuid,admin_user_id,form_inst_id,{
                sign_component_id:ds_no
            })
            threading.Thread(target=notify_signer,args=(participants_personal,form_uuid,form_inst_id,ds_no)).start()
            return ApiResponse.success(ds_no)
    return ApiResponse.fail("创建签署订单失败")

def notify_signer(participants_personal:list,form_uuid,form_inst_id,ds_no):
    for participant in participants_personal:
        yida_client.create_form_data(
            "FORM-6ABF70417C36461B94DCF647572F84B67EAC",
            admin_user_id,
            {
                "textField_lysafpzp":form_uuid,
                "textField_ls0gkw31": form_inst_id,
                "textField_lrzglud2": ds_no,
                "textField_lrzglud3": participant["dingtalkUserId"],
                "employeeField_ls0fsd2m": [participant["dingtalkUserId"]],
                "selectField_ls0fsd2n": "个人"
            }
        )
    

@csrf_exempt
@require_http_methods(["GET"])
def view_signed_file(request):
    order_no = request.GET.get("order_no")
    result = digital_sign_client.view_signed_file(order_no)
    redirect_url = result.get("data")
    if redirect_url:
        return redirect(redirect_url)
    else:
        return ApiResponse.fail("未找到报告")
    

def get_user_id(id_str):
    if not id_str:
        return None
    '''截取用户id'''
    if "-" in id_str:
        return id_str.split("-")[-1]
    else:
        return id_str
    
@csrf_exempt
@require_http_methods(["POST"])
def create_digital_sign_order(request):
    datasource: dict[str, any] = json.loads(request.body)
    form_inst_ids:list = datasource.get("form_inst_ids")
    report_results = yida_client.get_form_items_by_id_list("FORM-0BC04FECE4F544B297D37901915570D2OEIY",form_inst_ids,yida_client.admin_user_id)
    threading.Thread(target=create_digital_sign_order_thread,args=(form_inst_ids, report_results,)).start()
    return ApiResponse.success(message="订单创建成功")

def create_digital_sign_order_thread(form_inst_ids:list, report_info:list):
    for index, report_result in enumerate(report_info):
        form_data = report_result.form_data
        report_code = form_data.get("textField_lp93kxup")
        model_uuid = form_data.get("textField_lqbsdaaj")
        report_model = yida_client.get_form_data_by_search_field(
            "FORM-D4C9AA2AA5634D7CB46142B94F6B8441IA1U", admin_user_id, {"textField_lq966fhr": model_uuid})
        model_info = report_model[0].form_data
        app_history = yida_client.get_approve_history(form_inst_ids[index],admin_user_id)
        jcr1_id = get_user_id(form_data.get("selectField_lpgut0ng_id")) # 检测人1
        jcr2_id = get_user_id(form_data.get("selectField_lqeidrd3_id")) # 检测人2
        shr = next((item for item in reversed(app_history) if item.show_name == "待审核"), None) # 审核人
        pzr_id = next((item for item in reversed(app_history) if item.show_name == "总工审核"), None).operator_user_id # 批准人
        tl_id = get_user_id(form_data.get("selectField_lqvpbi42_id")) # 组长 专家组
        tm1_id = get_user_id(form_data.get("selectField_lqvpbi43_id")) # 组员1
        tm2_id = get_user_id(form_data.get("selectField_lqvpbi45_id")) # 组员2
        sign_areas_p = model_info['tableField_ls9optr6'] # 获取个人签署坐标配置
        participants_personal = []
        participants_p = [jcr1_id,jcr2_id]
        if model_uuid not in ["WVC66WC1M98HSGFSA8D4Q8XVZZWG3CM2G3WQLP47","H7D667C1FNCH7N0O683XH6RP8WN6281IG3WQLR7"]:
            # 评估和鉴定不加审核批准人
            if shr:
                participants_p += [shr.operator_user_id]
            participants_p += [pzr_id]
        if tl_id:
            participants_p += [tl_id, tm1_id, tm2_id]
        for index_area, sign_area in enumerate(sign_areas_p):
            if len(participants_p) <= index_area:
                continue
        #个人章
            participants_personal.append({
                "userType": "2",
                "dingtalkUserId": participants_p[index_area],
                "coordinate": rf'[{{"lby":{centimeter_transformation_point(sign_area["numberField_ls9optra"])},"lbx":{centimeter_transformation_point(sign_area["numberField_ls9optr9"])},"rty":{centimeter_transformation_point(sign_area["numberField_ls9optra"]) + centimeter_transformation_point(sign_area["numberField_ls9optro"])},"rtx":{centimeter_transformation_point(sign_area["numberField_ls9optr9"]) + centimeter_transformation_point(sign_area["numberField_ls9optro"])},"page":{sign_area["numberField_ls9optr7"]}}}]'
            })
        official_seal_areas = model_info.get("tableField_lt8ndw9l")
        
        official_seal_area_list = []
        for official_seal_area in official_seal_areas:# 获取企业章坐标配置
            seal = json.loads(json.loads(official_seal_area.get("associationFormField_lvdgd8ot_id")))[0]
            matching_items = [item for item in official_seal_area_list if item.get("sealFileUuid") == seal.get("subTitle")]
            if matching_items:
                official_coordinate = matching_items[0].get("coordinate_list")
            else:
                official_seal_info = {
                    "userType": "2",
                    "dingtalkUserId": pzr_id,
                    "sealFileUuid": seal.get("subTitle"),
                    "coordinate":"",
                    "coordinate_list":[],
                    "enterpriseCardno":"93k12jadfas01231203",
                    "coordinateRiding":f"{centimeter_transformation_point(official_seal_area['numberField_ls9optrm'])}F,{centimeter_transformation_point(official_seal_area['numberField_lt8ndw9m'])}F" if official_seal_area.get("numberField_ls9optrm") else None
                }
                official_seal_area_list.append(official_seal_info)
                official_coordinate = official_seal_info.get("coordinate_list")
            coordinate_item = {
                'lbx': centimeter_transformation_point(official_seal_area['numberField_lt8ndw9o']),
                'lby': centimeter_transformation_point(official_seal_area['numberField_lt8ndw9n']),
                'rtx': centimeter_transformation_point(official_seal_area['numberField_lt8ndw9o']) + centimeter_transformation_point(official_seal_area['numberField_lt8ndw9m']),
                'rty': centimeter_transformation_point(official_seal_area['numberField_lt8ndw9n']) + centimeter_transformation_point(official_seal_area['numberField_lt8ndw9m']),
                'page': official_seal_area['numberField_lt8ndw9p']
            }
            official_coordinate.append(coordinate_item)
        for seal_e in official_seal_area_list:
            seal_e["coordinate"] = json.dumps(seal_e["coordinate_list"])
        try:
            report = Report.objects.get(report_code=report_code)
        except Exception as err:
            raise Exception("未找到报告")
        data = {
            "participants": [],
            "callbackUrl":"https://api.zjcxjc.cn/api/v1/yida-app/chengxiang/sign-order-completed"
        }
        data["participants"].extend(participants_personal)
        data["participants"].extend(official_seal_area_list)
        res = digital_sign_client.create_order(data)
        if (res["code"] == 200):
            digital_bucket.copy_object(
                "xu-bk-chengxiang", f"{report.report_path}/whole.pdf", res['data']['contractFilePath']+'origin.pdf')
            ds_no = res["data"]["orderNum"]
            print('-',ds_no)
            report.digital_sign_order_no = ds_no
            report.save()
            # 宜搭自动化通知签署
            notify_p = list(set(participants_p))
            # 更新签署状态json字段
            if form_data.get("textField_ltmlzgdv"):
                sign_status = json.loads(form_data.get("textField_ltmlzgdv"))
            else:
                sign_status = {}
            sign_status['orderNo'] = ds_no
            sign_status["participants_p_list"] = notify_p
            status_str = json.dumps(sign_status)
            yida_client.update_form_data_by_id(
                "FORM-0BC04FECE4F544B297D37901915570D2OEIY",
                yida_client.admin_user_id,
                form_inst_ids[index],
                {
                    "textField_ltmlzgdv":status_str
                }
            )
            # 免验证签署人员
            no_verify_signer = [
                "024021201326222852",
                "4302516026430609",
                "1410641735697591",
                "032331201649699235",
                "0401131318699235"
            ]   
            for p_user_id in notify_p:
                if p_user_id in no_verify_signer:
                    try:
                        nv_result = digital_sign_client.sign_coordinate_pass_time(p_user_id,ds_no)
                    except Exception as err:
                        logger.error(err)
                    continue
                yida_client.create_form_data("FORM-6ABF70417C36461B94DCF647572F84B67EAC",
                                         yida_client.admin_user_id,
                                         {
                                              "textField_ls0gkw31": report_code,
                                              "textField_lrzglud2": ds_no,
                                              "textField_lrzglud3": p_user_id,
                                              "employeeField_ls0fsd2m": [p_user_id],
                                              "selectField_ls0fsd2n": "个人"
                                         })
            
        else:
            raise Exception("订单创建失败")